<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/axios.min.js"></script>
    <script src="/js/util.js"></script>
    <script>
        function  add(){
            //清空错误 提示
            $("nameSpan").innerHTML = "";
            $("phoneSpan").innerHTML = "";
            $("birthdaySpan").innerHTML = "";
            $("moneySpan").innerHTML = "";

           axios.get("/user/add",{
             params:{
               name:$("userName").value,
               phone:$("phone").value,
               money:$("money").value,
               birthday:$("birthday").value
             }
           }).then(resp =>{
              var info = resp.data;
              if(info == "ok"){
                 alert("添加成功");
              }
              else{//校验失败
                  info.forEach(n =>{
                     $(n.field + "Span").innerHTML = n.defaultMessage;
                  });
              }
           });
        }
    </script>
</head>
<body>
    用户名：<input type="text" id="userName">
          <span id="nameSpan"></span><br>
    电话：<input type="text" id="phone">
          <span id="phoneSpan"></span><br>
    工资：<input type="text" id="money">
          <span id="moneySpan"></span><br>
    生日：<input type="text" id="birthday">
        <span id="birthdaySpan"></span><br>
        <input type="button" value="添加" onclick="add()">
</body>
</html>